package com.ss.android.article.browser.main;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.MessageQueue;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.ViewTreeObserver;
import android.widget.AbsListView;
import android.widget.ImageView;

import com.bytedance.article.common.c.JSONObjectWrapper;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.c.SharedPreferenceCompat;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.common.utility.collection.WeakList;
import com.bytedance.frameworks.baselib.network.http.util.TaskInfo;
import com.ss.android.account.Spipe;
import com.ss.android.account.b.OnAccountRefreshListener;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.app.BizApplication;
import com.ss.android.article.base.app.MainActivityDelegate;
import com.ss.android.article.base.feature.category.a.CategoryManager;
import com.ss.android.article.base.feature.category.activity.CategoryTabStrip;
import com.ss.android.article.base.feature.feed.activity.ArticleRecentFragment;
import com.ss.android.article.base.feature.feed.presenter.WebArticlePreloadHelper;
import com.ss.android.article.base.feature.main.FeedShowDetector;
import com.ss.android.article.base.feature.main.IRecentFragment;
import com.ss.android.article.base.feature.main.SubscriptionPagerAdapter;
import com.ss.android.article.base.feature.model.CategoryItem;
import com.ss.android.article.base.feature.search.BaseDiscoverActivity;
import com.ss.android.article.base.feature.search.SearchActivity;
import com.ss.android.article.base.feature.update.b.UpdateItemMgr;
import com.ss.android.article.base.feature.video.IVideoController;
import com.ss.android.article.common.e.VideoControllerSupplierProxy;
import com.ss.android.common.app.AbsFragment;
import com.ss.android.common.callback.CallbackCenter;
import com.ss.android.common.callback.SSCallback;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.location.LocationHelper;
import com.ss.android.common.location.LocationUploadHelper;
import com.ss.android.common.location.ServerLocationChangeHelper;
import com.ss.android.common.util.ImmersedStatusBarHelper;
import com.ss.android.common.util.NetworkStatusMonitor;
import com.ss.android.messagebus.SubscriptionRouter;
import com.ss.android.newmedia.a.OnPageScrolledListener;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class BaseHomePageFragment extends AbsFragment implements
        com.b.a.a.a,
        WeakHandler.Callback,
        OnAccountRefreshListener,
        MainActivityDelegate,
        CategoryManager.a$a,
        FeedShowDetector.FeedShowDetector2 {
    static final String TAG = BaseHomePageFragment.class.getSimpleName();
    public final List<CategoryItem> mCategoryItemList;
    final Handler mHandler;
    public AppData mAppData;
    public ViewPager mViewPager;
    public MotionDirectionFrameLayout mMotionDirectionFrameLayout;
    public boolean n;
    public int o;
    public boolean p;
    public SubscriptionPagerAdapter mSubscriptionPagerAdapter;
    public int t;
    protected IVideoController mVideoController;
    protected View mHomePageFakeSearchLayout;
    protected View mFeedAreaContainer;
    protected int mNavigationGridHeight;
    protected BrowserGuideView mBrowserGuideView;
    CategoryTabStrip mCategoryTabStrip;
    boolean r;
    CategoryManager mCategoryManager;
    String mCategoryName;
    long mEnterTs;
    int w;
    private int A;
    private ViewGroup mContentView;
    private NetworkStatusMonitor mNetworkStatusMonitor;
    private WebArticlePreloadHelper mWebArticlePreloadHelper;
    private boolean E;
    private WeakList F;
    private boolean G;
    private boolean H;
    private View.OnClickListener I;
    private FeedShowDetector mFeedShowDetector;
    private boolean K;
    private Bundle mBundle;
    private FragmentActivity mFragmentActivity;
    private boolean N;
    private boolean O;
    private boolean P;
    private int[] Q;
    private SSCallback mSSCallback;
    private boolean mViewUpdate;
    private boolean mViewCategory;
    private String mGdExtJson;
    private String V;
    private boolean W;
    private OnPageScrolledListener mOnPageScrolledListener;
    private ScrollTopLayout mScrollTopLayout;
    private boolean Z;
    private Spipe a;
    private boolean aa;
    private TaskInfo mTaskInfo;
    private View y;
    private ViewStub z;

    public BaseHomePageFragment() {
        this.mHandler = new WeakHandler(((WeakHandler.Callback) this));
        this.mCategoryItemList = new ArrayList();
        this.A = -1;
        this.p = true;
        this.E = false;
        this.F = new WeakList();
        this.G = false;
        this.t = 1;
        this.mCategoryName = null;
        this.mEnterTs = 0;
        this.H = false;
        this.I = new View.OnClickListener() {

            public final void onClick(View arg4) {
                MobClickCombiner.onEvent(getContext(), "search_tab", "enter_home");
                Intent intent = new Intent(getContext(), SearchActivity.class);
                intent.putExtra("from", "search_tab");
                startActivity(intent);
            }
        };
        this.N = true;
        this.O = false;
        this.P = false;
        this.Q = new int[7];
        this.mSSCallback = new SSCallback() {
            public final Object onCallback(Object[] args) {
                return null;
            }
        };
        this.mViewUpdate = false;
        this.mViewCategory = false;
        new LinkedList();
        this.Z = true;
        this.aa = true;
    }


    public static void a(String arg5, int arg6, CategoryItem categoryItem) {
        if (categoryItem != null) {
            JSONObjectWrapper jsonObjectWrapper = new JSONObjectWrapper();
            if (arg6 == 2) {
                jsonObjectWrapper.put("enter_type", "click");
            } else if (arg6 == 1) {
                jsonObjectWrapper.put("enter_type", "flip");
            }

            jsonObjectWrapper.put("category_name", categoryItem.category)
                    .put("category_id", categoryItem.categoryId)
                    .put("concern_id", categoryItem.concernId)
                    .put("refer", Integer.valueOf(1));
            if (AppData.getInstance().getAbSettings().isApplogStaging()) {
                jsonObjectWrapper.put("_staging_flag", Integer.valueOf(1));
            }
            jsonObjectWrapper.put(null);
            android.support.design.a.onEvent(arg5, jsonObjectWrapper.jo);
        }
    }

    final void A() {
        Object v2 = null;
        if ((this.isViewValid()) && this.mCategoryManager != null) {
            ArrayList v4 = new ArrayList(this.mCategoryManager.a.values());
            int v0 = this.mViewPager.getCurrentItem() + 1;
            Object v1 = v0 < 0 || v0 >= this.mCategoryItemList.size() ? v2 : this.mCategoryItemList.get(v0);
            v0 = this.mViewPager.getCurrentItem();
            if (v0 >= 0 && v0 < ((List) v4).size()) {
                v2 = ((List) v4).get(v0);
            }
            this.mCategoryItemList.clear();
            this.mCategoryItemList.addAll(v4);
            this.mCategoryTabStrip.a();
            this.a(this.mCategoryItemList);
            this.mSubscriptionPagerAdapter.notifyDataSetChanged();
            this.E = false;
            try {
                if (this.Q.length < this.mSubscriptionPagerAdapter.getCount()) {
                    int[] v4_1 = new int[this.mSubscriptionPagerAdapter.getCount()];
                    int v5 = this.Q.length;
                    for (int i = 0; i < v5; ++i) {
                        v4_1[i] = this.Q[i];
                    }
                    this.Q = v4_1;
                }
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }

            if (v1 == null) {
                return;
            }

            if (v2 == null) {
                return;
            }

            if (!android.support.design.a.isTextEquals(((CategoryItem) v1).category, ((CategoryItem) v2).category)) {
                return;
            }

            if (!this.isActive()) {
                return;
            }

            Fragment fragment = this.mSubscriptionPagerAdapter.findFragment(this.mViewPager.getCurrentItem());
            if ((fragment instanceof IRecentFragment)) {
                ((IRecentFragment) fragment).onSetAsPrimaryPage(1);
            }


        }
    }

    protected final void checkCategoryTip() {
        int v6 = 16;
        Logger.d(BaseHomePageFragment.TAG, "checkCategoryTip " + this.mCategoryManager.mRecommendCategoryItem.category);
        this.mAppData.a(this.mCategoryManager.mRecommendCategoryItem.category, this.getUseTabTip(), true, false);
        if (!this.mHandler.hasMessages(v6)) {
            this.mHandler.sendEmptyMessageDelayed(v6, this.mAppData.M() * 1000);
        }
    }

    public final void a(String arg10, String arg11, int arg12) {
        long v4 = 0;
        if (arg12 >= 0 && arg12 <= this.mCategoryItemList.size() - 1) {
            Object v0 = this.mCategoryItemList.get(arg12);
            if (v0 == null) {
                MobClickCombiner.onEvent(this.getContext(), arg10, arg11);
            } else {
                JSONObject v8 = new JSONObject();
                try {
                    v8.put("category_id", ((CategoryItem) v0).categoryId);
                    v8.put("concern_id", ((CategoryItem) v0).concernId);
                    v8.put("refer", 1);
                } catch (JSONException v0_1) {
                    v0_1.printStackTrace();
                }

                MobClickCombiner.onEvent(this.getContext(), arg10, arg11, v4, v4, v8);
            }
        } else {
            MobClickCombiner.onEvent(this.getContext(), arg10, arg11);
        }
    }

    private void reportCategoryRefresh(String categoryName, String refreshType) {
        Bundle bundle = new Bundle();
        CategoryItem categoryItem = CategoryManager.getInstance(getActivity()).getCategoryItem(categoryName);
        bundle.putString("category_name", categoryName);
        bundle.putString("refresh_type", refreshType);
        bundle.putInt("refer", 1);
        bundle.putString("concern_id", categoryItem.concernId);
        android.support.design.a.onEvent("category_refresh", bundle);
    }

    private void a(List<CategoryItem> arg5) {
        ArrayList v1 = new ArrayList();
        Iterator<CategoryItem> v2 = arg5.iterator();
        while (v2.hasNext()) {
            v1.add(v2.next().name);
        }

        AppData.getInstance();
        SharedPreferences v0 = AppData.getAppSettingSp(this.getContext());
        String v2_1 = v0.getString("CATEGORY_STRING", "");
        if (!android.support.design.a.isTextEmpty(v2_1) && !v2_1.equals(v1.toString())) {
            MobClickCombiner.onEvent(this.getContext(), "category_changed");
        }

        SharedPreferences.Editor v0_1 = v0.edit();
        v0_1.putString("CATEGORY_STRING", v1.toString());
        SharedPreferenceCompat.commit(v0_1);
    }

    public final void onNewIntent(Bundle bundle) {
        if (bundle != null) {
            this.mViewUpdate = bundle.getBoolean("view_update", false);
            this.mViewCategory = bundle.getBoolean("view_category", false);
            if (this.mViewCategory) {
                this.mViewUpdate = false;
            }
            if (!this.mViewUpdate && !this.mViewCategory) {
                this.mBundle = bundle;
            }

            this.mGdExtJson = bundle.getString("gd_ext_json");
        }
    }

    public final void setOnPageScrolledListener(OnPageScrolledListener arg1) {
        this.mOnPageScrolledListener = arg1;
    }

    public final void a(boolean arg2) {
        ((ArticleMainActivity) getActivity()).updataVideoView(arg2);
    }

    @Deprecated
    public void addDelayInitCallback(DelayInitCallback delayInitCallback) {
        throw new UnsupportedOperationException("please call MainActivity.addDelayInitCallback() instead");
    }

    public void addIRecentFragment(IRecentFragment recentFragment) {
        if (recentFragment != null) {
            this.F.add(recentFragment);
        }
    }

    private void b(String arg2, String arg3) {
        MobClickCombiner.onEvent(this.getContext(), arg2, arg3);
    }

    final View findViewById(@IdRes int resId) {
        return this.mContentView.findViewById(resId);
    }

    public final void b() {
        Iterator v1 = this.F.iterator();
        while (v1.hasNext()) {
            Object v0 = v1.next();
            if (v0 == null) {
                continue;
            }

            ((IRecentFragment) v0).afterFeedShowOnResumed();
        }

        com.ss.android.l.c.c();
    }

    public final void b(boolean arg3) {
        if (!arg3) {
            if (this.z != null) {
                this.z.setVisibility(View.VISIBLE);
            }
        } else if (this.z != null) {
            this.z.setVisibility(View.GONE);
        }
    }

    public final void c() {
        Fragment v0 = this.mSubscriptionPagerAdapter.findFragment(this.mViewPager.getCurrentItem());
        if (v0 != null) {
            ((IRecentFragment) v0).handleRefreshClick(4);
            if (this.V != null) {
                this.reportCategoryRefresh(this.V, "button");
            }
        }
    }

    public final void c(boolean arg2) {
        if (this.isViewValid()) {
            if ((this.isActive()) && (this.r)) {
                this.A();
                return;
            }

            this.E = true;
        }
    }

    public boolean canShowNotify() {
        return true;
    }

    private JSONObject d() {
        JSONObject v0_1 = null;
        try {
            v0_1 = new JSONObject();
            v0_1.put("category_id", this.mCategoryName);
            v0_1.put("refer", 1);
        } catch (JSONException v1_1) {
        }

        return v0_1;
    }

    protected void d(boolean arg7) {
        this.Z = true;
        if (this.mMotionDirectionFrameLayout != null) {
            MotionDirectionFrameLayout v0 = this.mMotionDirectionFrameLayout;
            if (v0.ayVar != null) {
                v0.ayVar.a(200f);
            }
        }

        if ((this.getCurrentFragment() instanceof ArticleRecentFragment)) {
            AbsListView v0_1 = ((ArticleRecentFragment) this.getCurrentFragment()).getListView();
            try {
                Field v1 = AbsListView.class.getDeclaredField("mFlingRunnable");
                v1.setAccessible(true);
                Method v2 = v1.getType().getDeclaredMethod("endFling");
                v2.setAccessible(true);
                v2.invoke(v1.get(v0_1));
            } catch (Exception v0_2) {
            }

            ((ArticleRecentFragment) this.getCurrentFragment()).getListView().setSelection(0);
        }
    }

    public boolean doBackPressRefresh() {
        int v5 = 4;
        Fragment v0 = this.mSubscriptionPagerAdapter.findFragment(this.mViewPager.getCurrentItem());
        if (v0 != null) {
            if (AppData.getInstance().getAbSettings().isBackRefreshInCategoryAll()) {
                String v1 = ((IRecentFragment) v0).getCategory();
                if (v1.equals("__all__")) {
                    ((IRecentFragment) v0).handleRefreshClick(v5);
                    this.reportCategoryRefresh("__all__", "click_return");
                } else if (this.mViewPager != null && this.mSubscriptionPagerAdapter != null) {
                    v0 = this.mSubscriptionPagerAdapter.findFragment(0);
                    if (v0 != null) {
                        ((IRecentFragment) v0).setBackRefreshSwitch(true);
                        this.mViewPager.setCurrentItem(0, false);
                    } else {
                        this.mViewPager.setCurrentItem(0, false);
                        ((IRecentFragment) this.mSubscriptionPagerAdapter.findFragment(0)).setBackRefreshSwitch(true);
                    }

                    this.V = v1;
                }
            } else {
                ((IRecentFragment) v0).handleRefreshClick(v5);
            }
        }

        return true;
    }

    private void e() {
        this.W = true;
        this.checkCategoryTip();
    }

    public String getCategory() {
        String v0_2;
        String v1 = "__all__";
        int v0 = this.mViewPager.getCurrentItem();
        if (v0 < 0 || v0 >= this.mCategoryItemList.size()) {
            label_15:
            v0_2 = v1;
        } else {
            Object v0_1 = this.mCategoryItemList.get(v0);
            if (v0_1 == null) {
                v0_2 = v1;
            } else if (!TextUtils.isEmpty(((CategoryItem) v0_1).category)) {
                v0_2 = ((CategoryItem) v0_1).category;
            } else {
                v0_2 = v1;
            }
        }
        return v0_2;
    }

    public Fragment getCurrentFragment() {
        return this.mSubscriptionPagerAdapter == null || this.mViewPager == null ? null : this.mSubscriptionPagerAdapter.findFragment(this.mViewPager.getCurrentItem());
    }

    public void getCurrentList(int arg3, List result) {
        IRecentFragment recentFragment = null;
        if (this.mSubscriptionPagerAdapter != null) {
            recentFragment = this.mSubscriptionPagerAdapter.d();
        }

        if (recentFragment instanceof ArticleRecentFragment) {
            ((ArticleRecentFragment) recentFragment).getCurrentList(arg3, result);
        }
    }

    public int getFirstVisiblePosition() {
        Fragment v0 = this.mSubscriptionPagerAdapter.findFragment(this.mViewPager.getCurrentItem());
        int v0_1 = v0 != null ? ((IRecentFragment) v0).getFirstVisiblePosition() : 0;
        return v0_1;
    }

    public WebArticlePreloadHelper getPreloadHelper() {
        return this.mWebArticlePreloadHelper;
    }

    public boolean getUseTabTip() {
        boolean v0 = true;
        if (this.A == -1) {
            int v2 = AppData.getInstance().useTabTip != 0 ? 1 : 0;
            if (v2 != 0) {
                this.A = 1;
//                goto label_11;
            } else {
                this.A = 0;
            }
        }

        label_11:
        if (this.A == 0) {
            v0 = false;
        }

        return v0;
    }

    public void handleCategoryTip(String category, String tip, String count) {
        int v0_2;
        if (!android.support.design.a.isTextEmpty(category) && !"subscription".equals(category)) {
            boolean v0 = this.getUseTabTip();
            if (this.mCategoryManager != null) {
                this.mCategoryManager.mRecommendCategoryItem.category.equals(category);
            }

            if (v0) {
                Fragment v1 = this.mSubscriptionPagerAdapter.findFragment(this.mViewPager.getCurrentItem());
                if (!(v1 instanceof ArticleRecentFragment)) {
                    return;
                }

                if (!category.equals(((ArticleRecentFragment) v1).getCategoryCity())) {
                    return;
                }

                ((ArticleMainActivity) getActivity()).setRedPoint(true, count);
                try {
                    v0_2 = Integer.valueOf(count).intValue();
                } catch (Exception v0_1) {
                    v0_1.printStackTrace();
                    v0_2 = 0;
                }

                if (v0_2 > 0) {
                    ((ArticleRecentFragment) v1).setHasTips(true);
                    return;
                }

                ((ArticleRecentFragment) v1).setHasTips(false);
                return;
            }

            Iterator v1_1 = this.F.iterator();
            while (v1_1.hasNext()) {
                Object v0_3 = v1_1.next();
                if (!(v0_3 instanceof ArticleRecentFragment)) {
                    continue;
                }

                ((ArticleRecentFragment) v0_3).handleCategoryTip(category, tip);
            }
        }
    }

    public void handleMsg(Message message) {
        if (this.isViewValid()) {
            Logger.d(BaseHomePageFragment.TAG, "handleMsg: " + message.what);
            switch (message.what) {
                case 11:
                    if (this.isViewValid()) {
                        this.mHandler.removeMessages(11);
                    }
                    return;
                case 12:
                    Fragment v0 = this.mSubscriptionPagerAdapter.findFragment(this.mViewPager.getCurrentItem());
                    if ((v0 instanceof ArticleRecentFragment)) {
                        ((ArticleRecentFragment) v0).onPullRefresh();
                        return;
                    }
                case 14:
                    if (!this.r) {
                        this.r = true;
                        this.mHandler.sendEmptyMessageDelayed(15, 5000);
                        return;
                    }
                    return;
                case 15:
                    if (!CategoryTabStrip.b()) {
                        com.bytedance.article.common.a.g.serviceMonitor("cate_not_draw", 0, null);
                        Logger.d(BaseHomePageFragment.TAG, "Category is not drawn.");
                        return;
                    }
                    return;
                case 16:
                    this.checkCategoryTip();
                    return;
            }
            return;
        }
    }

    public boolean isPrimaryPage(IRecentFragment recentFragment) {
        boolean v0_2;
        int v0_1;
        if (this.mSubscriptionPagerAdapter != null) {
            SubscriptionPagerAdapter v0 = this.mSubscriptionPagerAdapter;
            int v3 = recentFragment == null || v0.a == null || recentFragment != v0.a.get() ? 0 : 1;
            if (v3 != 0 || v0.mViewPager == null || !(recentFragment instanceof com.ss.android.article.base.feature.feed.bb)) {
                label_36:
                v0_1 = v3;
            } else {
                String v4 = ((com.ss.android.article.base.feature.feed.bb) recentFragment).getCategory();
                int v5 = v0.mViewPager.getCurrentItem();
                if (v5 < 0) {
                    v0_1 = v3;
                } else if (v5 >= v0.mCategoryItemList.size()) {
                    v0_1 = v3;
                } else if (v4 == null) {
                    v0_1 = v3;
                } else if (v4.equals(v0.mCategoryItemList.get(v5).category)) {
                    v0_1 = 1;
                } else {
                    v0_1 = v3;
                }
            }

            if (v0_1 == 0) {
                v0_2 = false;
            } else {
                v0_2 = true;
            }
        } else {
            label_38:
            v0_2 = false;
        }

        return v0_2;
    }

    public boolean isViewCategory() {
        return true;
    }

    public void onAccountRefresh(boolean arg1, int arg2) {
    }

    public void onActivityCreated(@Nullable Bundle arg5) {
        super.onActivityCreated(arg5);
        this.w();
        com.ss.android.l.c.c();
        if (this.mBundle != null && this.mBundle.getInt("sso_auth_ext_value", 0) > 0) {
            this.getContext();
            Spipe.d();
        }

        if (!BizApplication.k()) {
            this.b("topic", "init_topic_false");
        }

        if (this.mViewPager != null && this.mViewPager.getCurrentItem() == 0) {
            this.O = true;
        }

        this.P = true;
    }

    public void onBackPressRefresh() {
        Fragment v0 = this.mSubscriptionPagerAdapter.findFragment(this.mViewPager.getCurrentItem());
        if (v0 != null) {
            ((IRecentFragment) v0).handleRefreshClick(4);
            if (this.V != null) {
                this.reportCategoryRefresh(this.V, "click_return");
            }
        }
    }

    public void onCreate(Bundle bundle) {
        int v7 = 600;
        com.ss.android.article.base.utils.e.e();
        com.ss.android.article.base.utils.e.a(10005);
        com.ss.android.l.c.c();
        super.onCreate(bundle);
        com.ss.android.l.c.c();
        this.mAppData = AppData.getInstance();
        AppData.isNightMode();
        SubscriptionRouter.addSubscriber(this);
        if (Logger.debug()) {
            Logger.d("ObserverManager", "register " + BaseHomePageFragment.TAG);
        }

        this.mNetworkStatusMonitor = new NetworkStatusMonitor(this.getContext());
        if (bundle != null && (bundle.containsKey("isTabEnableFloatRefresh"))) {
            bundle.getBoolean("isTabEnableFloatRefresh");
        }

        com.ss.android.l.c.c();
        this.mAppData = AppData.getInstance();
        this.a = Spipe.inst();
        this.a.addOnAccountRefreshListener(((OnAccountRefreshListener) this));
        this.mAppData.T = new WeakReference(this);
        this.mAppData.T();
        UpdateItemMgr.a(this.getContext(), "digg");
        UpdateItemMgr.a(this.getContext(), "comment");
        UpdateItemMgr.b(this.getContext());
        this.mTaskInfo = new TaskInfo();
        AppData v0 = this.mAppData;
        Context v1 = this.getContext();
        LocationUploadHelper v2 = LocationUploadHelper.a(v1);
        Bundle v3 = new Bundle();
        v3.putBoolean("is_sys_locale_upload", v0.isSysLocaleUpload);
        v3.putBoolean("is_baidu_locale_upload", v0.isBaiduLocaleUpload);
        v3.putBoolean("is_gaode_locale_upload", v0.isGaodeLocaleUpload);
        v3.putBoolean("is_locale_request_gps", v0.isLocaleRequestGps);
        v3.putInt("locale_upload_interval", v0.lbsSyncInterval);
        v2.h = v3.getBoolean("is_sys_locale_upload", true);
        v2.i = v3.getBoolean("is_gaode_locale_upload", true);
        v2.m = v3.getBoolean("is_locale_request_gps", false);
        int v3_1 = v3.getInt("locale_upload_interval", v7);
        if (v3_1 >= v7) {
            v2.l = v3_1;
        }

        ServerLocationChangeHelper v2_1 = new ServerLocationChangeHelper(v1);
        v3_1 = v0.lbsAlertInterval;
        if (v3_1 >= v7) {
            v2_1.c = v3_1;
            v2_1.d = v3_1;
            v2_1.a.edit().putInt("dialog_show_interval", v3_1).commit();
        }

        LocationHelper.getInstance(v1);
        LocationHelper.a(v0.lbsLocateInterval);
        LocationUploadHelper.a(this.getContext());
        LocationUploadHelper.a(this.mAppData);
        CallbackCenter.addCallback(com.ss.android.j.b.callbackTypeNightModeChanged, this.mSSCallback);
        getActivity().getWindow().getDecorView().getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

            public final boolean onPreDraw() {
                getActivity().getWindow().getDecorView().getViewTreeObserver().removeOnPreDrawListener(this);
                BaseHomePageFragment.this.r = true;
                Looper.myQueue().addIdleHandler(new MessageQueue.IdleHandler() {

                    public final boolean queueIdle() {
                        BaseHomePageFragment.this.A();
                        return false;
                    }
                });
                return true;
            }
        });
        com.ss.android.l.c.c();
        Bundle v0_1 = this.getArguments();
        if (v0_1 != null) {
            this.K = v0_1.getBoolean("view_update", false);
            this.mViewCategory = v0_1.getBoolean("view_category", false);
            this.mViewUpdate = this.K;
            if (this.mViewCategory) {
                this.mViewUpdate = false;
            }

            if (!this.mViewUpdate && !this.mViewCategory) {
                this.mBundle = v0_1;
            }

            this.mGdExtJson = v0_1.getString("gd_ext_json");
        }

        this.mFragmentActivity = ((ArticleMainActivity) getActivity());
        if (this.mFragmentActivity != null) {
            this.mFragmentActivity.getWindow().getDecorView().getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

                public final boolean onPreDraw() {
                    BaseHomePageFragment.this.mFragmentActivity.getWindow().getDecorView().getViewTreeObserver().removeOnPreDrawListener(this);
                    mHandler.sendEmptyMessage(14);
                    return true;
                }
            });
        }

        this.mCategoryManager = CategoryManager.getInstance(this.getContext());
        this.mFeedShowDetector = new FeedShowDetector(this);
        this.mFeedShowDetector.a();
        this.mVideoController = VideoControllerSupplierProxy.getInstance().getVideoControllerInstance();
        this.b("lite_ui_version", "channel");
    }

    @Nullable
    public View onCreateView(LayoutInflater arg3, @Nullable ViewGroup arg4, @Nullable Bundle arg5) {
        com.ss.android.l.c.c();
        this.mContentView = (ViewGroup) arg3.inflate(com.ss.android.article.browser.R.layout.fc, arg4, false);
        return this.mContentView;
    }

    public void onDestroy() {
        super.onDestroy();
        SubscriptionRouter.removeSubscriber(this);
        super.onDestroy();
        SubscriptionRouter.removeSubscriber(this);
        if (this.mNetworkStatusMonitor != null) {
            this.mNetworkStatusMonitor.onDestroy();
        }

        if (this.mFeedShowDetector != null) {
            this.mFeedShowDetector.b();
        }

        this.mHandler.removeMessages(11);
        if (this.mTaskInfo != null) {
            this.mTaskInfo.a = true;
        }

        if (this.a != null) {
            this.a.b(((OnAccountRefreshListener) this));
        }

        LocationUploadHelper.a(this.getContext());
        LocationUploadHelper.b(this.mAppData);
        if (this.mVideoController != null) {
            this.mVideoController.onActivityDestroy();
        }

        VideoControllerSupplierProxy.getInstance().releaseVideoControllerInstance();
        com.ss.android.article.common.e.a.a().a(true);
        CategoryManager categoryManager = CategoryManager.getInstance(this.getContext());
        if (this != null) {
            categoryManager.mHomePageList.remove(this);
        }
    }

    public void onFeedShow(boolean arg1) {
        this.e();
    }

    public void onLastReadShow() {
    }

    public void onListViewScrollStateChanged(int arg1) {
    }

    public void onLoadingStatusChanged(IRecentFragment arg2) {
    }

    public void onPause() {
        super.onPause();
        this.onEnterOrLeavePage();
    }

    public void onResume() {
        JSONObject v8_1 = null;
        int v1_4;
        long v2 = 7200000;
        Bundle v0 = null;
        long v4 = 0;
        this.mAppData.b.weakHashMap.clear();
        AppData appData = this.mAppData;
        if (appData.mTryShowDislikeReadingDlgCount < 4) {
            ++appData.mTryShowDislikeReadingDlgCount;
            SharedPreferences.Editor editor = appData.mContext.getSharedPreferences("app_setting", 0).edit();
            editor.putInt("try_show_dislike_reading_dlg_count", appData.mTryShowDislikeReadingDlgCount);
            SharedPreferenceCompat.commit(editor);
        }

        super.onResume();
        com.ss.android.l.c.c();
        com.ss.android.l.c.c();
        this.mNetworkStatusMonitor.registerNetworkStateReceiver();
        com.ss.android.l.c.c();
        com.ss.android.l.c.c();
        boolean v1_1 = AppData.isNightMode();
        if (this.G != v1_1) {
            this.G = v1_1;
        }

        com.ss.android.l.c.c();
        if (this.mViewUpdate) {
            MobClickCombiner.onEvent(this.getContext(), "explore", "enter_click");
            this.startActivity(new Intent(this.getContext(), BaseDiscoverActivity.class));
            this.mViewUpdate = false;
            this.mViewCategory = false;
        }

        if (this.mViewCategory) {
            this.mViewCategory = false;
        }

        if (this.mBundle != null) {
            Bundle v1_2 = this.mBundle;
            if (v1_2 != null) {
                String v1_3 = v1_2.getString("open_category_name");
                if (!android.support.design.a.isTextEmpty(v1_3)) {
                    v1_4 = this.mCategoryItemList.indexOf(CategoryManager.getInstance(this.getContext()).getCategoryItem(v1_3));
                    if (v1_4 >= 0) {
                        this.mViewPager.setCurrentItem(v1_4, false);
                    }
                }
            }

            this.mBundle = v0;
        }

        long v6_1 = this.mAppData.cJ;
        if (!this.H && v6_1 > v4) {
            long v8 = System.currentTimeMillis() - v6_1;
            v6_1 = ((long) this.mAppData.mCategoryForceStreamInterval);
            if (v6_1 <= v4) {
                v2 = 86400000;
            } else if (v6_1 >= v2) {
                v2 = v6_1;
            }

            if (v8 <= v2) {
//                goto label_88;
            } else {
                this.mViewPager.setCurrentItem(0);
            }
        }

//        label_88:
        this.H = false;
        if (((this.O) || (this.P)) && !android.support.design.a.isTextEmpty(this.mGdExtJson)) {
            try {
                v8_1 = new JSONObject(this.mGdExtJson);
            } catch (Exception e) {
            }
        } else {
            v8_1 = null;
        }
        label_99:
        if (this.O) {
            this.O = false;
            if (this.mViewPager != null && this.mViewPager.getCurrentItem() == 0) {
                MobClickCombiner.onEvent(this.getContext(), "new_tab", "enter_launch", v4, v4, v8_1);
            }
        }

        if (this.N) {
            this.N = false;
        }

        v1_4 = this.mViewPager.getCurrentItem();
        if (!this.isViewCategory() || v1_4 < 0 || v1_4 >= this.mCategoryItemList.size()) {
            this.mCategoryName = null;
            this.mEnterTs = v4;
        } else {
            this.mCategoryName = this.mCategoryItemList.get(v1_4).category;
            this.mEnterTs = System.currentTimeMillis();
        }

        if ((this.E) && (this.r)) {
            this.A();
        }

        System.currentTimeMillis();
        if (this.W) {
            this.checkCategoryTip();
        }
        com.bytedance.ttstat.a.q(((ArticleMainActivity) getActivity()));
    }

    public void onUserPullToRefresh() {
    }

    public void onWaitFeedTimeout() {
        this.e();
    }

    public final boolean q_() {
        boolean v0_1;
        Fragment v0 = this.mSubscriptionPagerAdapter.findFragment(this.mViewPager.getCurrentItem());
        if (!this.isViewValid() || !(v0 instanceof ArticleRecentFragment)) {
            v0_1 = false;
        } else {
            ((ArticleRecentFragment) v0).doPullDownToRefresh();
            v0_1 = true;
        }

        return v0_1;
    }

    @Deprecated
    public void removeDelayInitCallback(DelayInitCallback delayInitCallback) {
        throw new UnsupportedOperationException("please call MainActivity.removeDelayInitCallback() instead");
    }

    public boolean showTipsFor(String arg2) {
        boolean v0 = "__all__".equals(arg2) ? true : false;
        return v0;
    }

    public void switchCategory(CategoryItem categoryItem, int arg5) {
        this.t = arg5;
        if (this.mSubscriptionPagerAdapter != null) {
            int v0 = this.mCategoryItemList.indexOf(categoryItem);
            if (v0 >= 0 && v0 != this.mViewPager.getCurrentItem()) {
                this.mViewPager.setCurrentItem(v0, false);
            }
        }
    }

    public void updateCategoryTip(String arg1) {
    }

    protected void w() {
        mContentView.findViewById(com.ss.android.article.browser.R.id.content_layout);
        this.mWebArticlePreloadHelper = new WebArticlePreloadHelper(this.getContext(), this.mNetworkStatusMonitor);
        this.registerLifeCycleMonitor(this.mWebArticlePreloadHelper);
        this.mViewPager = mContentView.findViewById(com.ss.android.article.browser.R.id.view_pager);
        this.mSubscriptionPagerAdapter = new SubscriptionPagerAdapter(this.getChildFragmentManager(), this.mCategoryItemList, this.mViewPager, new SubscriptionPagerAdapter.a$a(this));
        this.mViewPager.setAdapter(this.mSubscriptionPagerAdapter);
        this.mCategoryManager.mHomePageList.add(this);
        this.mCategoryManager.a(false);
        this.c(false);
        int index = 0;
        if (this.mBundle != null) {
            CategoryItem categoryItem = this.mCategoryManager.getCategoryItem(this.mBundle.getString("category"));
            if (categoryItem != null) {
                index = this.mCategoryItemList.indexOf(categoryItem);
                if (index < 0) {
                    index = 0;
                }
            }
        }

        if (index > 0) {
            this.mViewPager.setCurrentItem(index);
            this.H = true;
        }

        ViewGroup v2 = this.mContentView;
        if (this.z == null) {
            this.z = ((View) v2).findViewById(com.ss.android.article.browser.R.id.z_);
            this.z.inflate();
        }

        if (this.z != null) {
            this.z.setVisibility(View.VISIBLE);
        }

        this.y = ((View) v2).findViewById(com.ss.android.article.browser.R.id.zc);
        UIUtils.setBackgroundResource(this.y, com.ss.android.article.browser.R.drawable.az);
        this.y.getLayoutParams().height = this.getResources().getDimensionPixelOffset(com.ss.android.article.browser.R.dimen.gq);
        this.mCategoryTabStrip = ((View) v2).findViewById(com.ss.android.article.browser.R.id.category_strip);
        this.mCategoryTabStrip.setShowBottomLine(true);
        this.mCategoryTabStrip.setTabTextSize(16f);
        this.mCategoryTabStrip.setIsScaleSelectedTabText(false);
        ImageView v1 = v2.findViewById(com.ss.android.article.browser.R.id.zg);
        Context v3 = this.getContext();
        if (v3 != null && ((v1 instanceof ImageView))) {
            com.ss.android.article.base.app.r.a();
            com.ss.android.article.base.app.r.b();
            AppData.getInstance();
            AppData.isNightMode();
            v1.setImageDrawable(android.support.design.a.a(ContextCompat.getDrawable(v3, com.ss.android.article.browser.R.drawable.va), Color.parseColor("#343434")));
        }

        View v0_3 = ((View) v2).findViewById(com.ss.android.article.browser.R.id.zf);
        Context v2_1 = this.getContext();
        if (v2_1 != null && v0_3 != null) {
            com.ss.android.article.base.app.r.a();
            com.ss.android.article.base.app.r.b();
            AppData.getInstance();
            AppData.isNightMode();
            ((ImageView) v0_3).setImageDrawable(ContextCompat.getDrawable(v2_1, com.ss.android.article.browser.R.drawable.vp));
        }

        ((ImageView) v0_3).setOnClickListener(this.I);
        v1.setOnClickListener(new View.OnClickListener() {
            public final void onClick(View view) {
                try {
                    android.support.design.a.onEvent("enter_tab", new JSONObjectWrapper().put("tab_name", "mine").jo);
                    Intent intent = new Intent();
                    intent.setClassName(getContext(), "com.ss.android.mine.MineActivity");
                    startActivity(intent);
                } catch (Throwable throwable) {
                    throwable.printStackTrace();
                }
            }
        });
        this.mCategoryTabStrip.setOnTabClickListener(new com.ss.android.article.base.feature.category.activity.CategoryTabStrip.CategoryTabStrip$d(this));
        this.mCategoryTabStrip.setViewPager(this.mViewPager);
        this.mCategoryTabStrip.setOnPageChangeListener(new OnPageScrolledListener() {

            public final void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                super.onPageScrolled(position, positionOffset, positionOffsetPixels);
                if (mOnPageScrolledListener != null) {
                    mOnPageScrolledListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
                }
            }

            public final void onPageSelected(int position) {
                Logger.v(BaseHomePageFragment.TAG, "onPageChanged " + position);
                onEnterOrLeavePage();
                Object v0 = mCategoryItemList.get(position);
                if (((CategoryItem) v0).type == 5) {
                    ((ArticleMainActivity) getActivity()).setRedPoint(false, "");
                }

                if (isViewCategory()) {
                    if ((mCategoryManager.mRecommendCategoryItem.category.equals(((CategoryItem) v0).category))
                            && !mCategoryName.equals(((CategoryItem) v0).category)
                            && ((getCurrentFragment() instanceof ArticleRecentFragment))) {
                        ((ArticleRecentFragment) getCurrentFragment()).onEnterFromOtherCategory();
                    }

                    mCategoryName = ((CategoryItem) v0).category;
                    mEnterTs = System.currentTimeMillis();
                } else {
                    mCategoryName = null;
                    mEnterTs = 0;
                }

                if (position >= 0 && position < mCategoryTabStrip.b.getChildCount()) {
                    mCategoryTabStrip.b(mCategoryTabStrip.b.getChildAt(position));
                }

                if (mOnPageScrolledListener != null) {
                    mOnPageScrolledListener.onPageSelected(position);
                }

                if (mMotionDirectionFrameLayout != null) {
                    mMotionDirectionFrameLayout.a();
                }
            }
        });
        this.mScrollTopLayout = (ScrollTopLayout) this.findViewById(com.ss.android.article.browser.R.id.browser_guid_scroll_top_layout);
        this.mFeedAreaContainer = this.findViewById(com.ss.android.article.browser.R.id.feed_area_container);
        this.mHomePageFakeSearchLayout = this.findViewById(com.ss.android.article.browser.R.id.home_page_fake_search_layout);
        this.findViewById(com.ss.android.article.browser.R.id.z9);
        this.mBrowserGuideView = (BrowserGuideView) this.findViewById(com.ss.android.article.browser.R.id.browser_guide_view);
        this.mMotionDirectionFrameLayout = (MotionDirectionFrameLayout) this.findViewById(com.ss.android.article.browser.R.id.feed_area_container);
        this.mScrollTopLayout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

            public final boolean onPreDraw() {
                mScrollTopLayout.getViewTreeObserver().removeOnPreDrawListener(this);
                int measuredHeight = mScrollTopLayout.getMeasuredHeight();
                int statusBarHeight = ImmersedStatusBarHelper.isEnabled() ? ImmersedStatusBarHelper.getStatusBarHeight(getContext(), true) : 0;
                mNavigationGridHeight = measuredHeight - statusBarHeight - mHomePageFakeSearchLayout.getMeasuredHeight();
                return false;
            }
        });
        this.mScrollTopLayout.setDispatchTouchListener(new View.OnTouchListener() {

            public final boolean onTouch(View v, MotionEvent motionEvent) {
                if (mMotionDirectionFrameLayout.getVisibility() != View.VISIBLE) {
                    return false;
                } else {
                    if (mMotionDirectionFrameLayout.ayVar != null) {
                        mMotionDirectionFrameLayout.ayVar.dispatchTouchEvent(motionEvent);
                    }
                    return true;
                }
            }
        });
        MotionDirectionScrollHelper.MotionHeaderScroller v1_1 = new MotionDirectionScrollHelper.MotionHeaderScroller() {
            private int a = UIUtils.getStatusBarHeight(getContext());
            private int b = getContext().getResources().getDimensionPixelOffset(com.ss.android.article.browser.R.dimen.c6);
            private int c = 0;

            public final int a() {
                return (int) ((double) (mScrollTopLayout.getHeight() * -1 + this.a) + (double) this.b * 1.2);
            }

            public final void a(boolean arg2) {
                if (arg2) {
                    BaseHomePageFragment.this.Z = false;
                }
            }

            public final boolean a(int deltaY) {
                boolean v0 = true;
                if (deltaY != 0) {
                    int v2 = this.c + deltaY;
                    int v3 = Math.min(Math.max(v2, this.a()), 0);
                    this.d(v3);
                    if (v3 != v2) {
                        v0 = false;
                    }
                }
                return v0;
            }

            public final int b() {
                return this.c;
            }

            public final void b(int arg1) {
                this.d(arg1);
            }

            public final boolean c(int arg6) {
                boolean v0;
                if (arg6 == 1) {
                    new com.ss.android.g.a.a$a("draw_feed").a("category_name", getCategory()).a().a();
                }

                if (!BaseHomePageFragment.this.Z) {
                    v0 = false;
                } else {
                    if (!BaseHomePageFragment.this.aa) {
                        v0 = !(BaseHomePageFragment.this.getCurrentFragment() instanceof ArticleRecentFragment) || ((ArticleRecentFragment) BaseHomePageFragment.this.getCurrentFragment()).isInListViewTop();
                        if (v0) {
                        } else {
                            return false;
                        }
                    }

                    float translationY = mScrollTopLayout.getTranslationY();
                    if (translationY == 0f && arg6 == 2 || translationY == (((float) this.a())) && arg6 == 1) {
                        return false;
                    }
                    v0 = true;
                }

                return v0;
            }

            private void d(int translationY) {
                this.c = translationY;
                BaseHomePageFragment.this.w = translationY;
                mBrowserGuideView.getPullRefreshContainer().setTranslationY(((float) translationY));
                if (translationY == this.a()) {
                    if (BaseHomePageFragment.this.aa) {
                        BaseHomePageFragment.this.aa = false;
                        if (BaseHomePageFragment.this.Z) {
                            BaseHomePageFragment.this.Z = false;
                        }
                    }
                } else if (translationY == 0 && !BaseHomePageFragment.this.aa) {
                    BaseHomePageFragment.this.aa = true;
                }

                this.a();
            }
        };
        if (mMotionDirectionFrameLayout.ayVar == null) {
            mMotionDirectionFrameLayout.ayVar = new MotionDirectionScrollHelper(mMotionDirectionFrameLayout.getContext(),
                    mMotionDirectionFrameLayout,
                    new MotionDirectionScrollHelper.TouchEventDispatcher(mMotionDirectionFrameLayout));
            mMotionDirectionFrameLayout.ayVar.e = 1;
        }

        mMotionDirectionFrameLayout.ayVar.d = ((MotionDirectionScrollHelper.MotionHeaderScroller) v1_1);
    }

    protected void y() {
    }

    final void onEnterOrLeavePage() {
        if (this.mEnterTs > 0L && !android.support.design.a.isTextEmpty(this.mCategoryName)) {
            long stayTime = System.currentTimeMillis() - this.mEnterTs;
            if (stayTime >= 5000L) {
                if (AppData.getInstance().getAbSettings().isAppLogOld()) {
                    MobClickCombiner.onEvent(this.getContext(), "stay_category", this.mCategoryName, stayTime, 0L, this.d());
                }

                if (AppData.getInstance().getAbSettings().isAppLogNew()) {
                    JSONObjectWrapper jsonObjectWrapper = new JSONObjectWrapper().put("stay_time", Long.valueOf(stayTime))
                            .put("enter_type", "click")
                            .put("category_name", this.mCategoryName)
                            .put(this.d());
                    if (AppData.getInstance().getAbSettings().isApplogStaging()) {
                        jsonObjectWrapper.put("_staging_flag", Integer.valueOf(1));
                    }
                    android.support.design.a.onEvent("stay_category", jsonObjectWrapper.jo);
                }
            }
        }
        this.mEnterTs = 0L;
    }
}

